package flc.ast;

import android.graphics.Color;
import android.view.View;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.SPUtils;

import java.util.ArrayList;
import java.util.List;

import flc.ast.bean.CycleBean;
import flc.ast.bean.HourWageBean;
import flc.ast.databinding.ActivityHomeBinding;
import flc.ast.fragment.ClockInFragment;
import flc.ast.fragment.HomeFragment;
import flc.ast.fragment.MyFragment;
import flc.ast.fragment.WorkTimeFragment;
import flc.ast.utils.AppSpUtils;
import flc.ast.utils.Content;
import stark.common.basic.base.BaseNoModelActivity;
import stark.common.basic.base.BaseTabFragmentHomeActivity;
import stark.common.basic.base.DefExitAppDialog;
import stark.common.basic.event.EventStatConstant;
import stark.common.basic.event.EventStatProxy;
import stark.common.basic.utils.SPUtil;

public class HomeActivity extends BaseTabFragmentHomeActivity<ActivityHomeBinding> implements View.OnClickListener {

    @Override
    protected int getPageType() {
        return EventStatConstant.PAGE_TAB_HOME;
    }

    @Override
    protected void initView() {
        super.initView();
        EventStatProxy.getInstance().statLaunch(this);
        boolean isInit = SPUtil.getBoolean(mContext, Content.isInit, false);
        if (!isInit) {
            List<HourWageBean> list = new ArrayList<>();
            list.add(new HourWageBean(getString(R.string.hour_wage_name1), 10));
            list.add(new HourWageBean(getString(R.string.hour_wage_name2), 20));
            AppSpUtils.saveWageList(list);
            List<CycleBean> listCycle = new ArrayList<>();
            listCycle.add(new CycleBean(getString(R.string.cycle_name1), 1, false));
            listCycle.add(new CycleBean(getString(R.string.cycle_name2), 2, true));
            listCycle.add(new CycleBean(getString(R.string.cycle_name3), 3, true));
            listCycle.add(new CycleBean(getString(R.string.cycle_name4), 4, true));
            listCycle.add(new CycleBean(getString(R.string.cycle_name5), 5, true));
            listCycle.add(new CycleBean(getString(R.string.cycle_name6), 6, true));
            listCycle.add(new CycleBean(getString(R.string.cycle_name7), 7, false));
            AppSpUtils.saveCycleList(listCycle);
            SPUtil.putBoolean(mContext, Content.isInit, true);
        }

    }

    @NonNull
    @Override
    protected List<BaseTabFragmentHomeActivity<ActivityHomeBinding>.FragmentViewBinder> getFragmentViewBinders() {
        List<FragmentViewBinder> listFragment = new ArrayList<>();
        listFragment.add(new FragmentViewBinder(HomeFragment.class, R.id.llHome));
        listFragment.add(new FragmentViewBinder(WorkTimeFragment.class, R.id.llWorkTime));
        listFragment.add(new FragmentViewBinder(ClockInFragment.class, R.id.llClockIn));
        listFragment.add(new FragmentViewBinder(MyFragment.class, R.id.llMy));
        return listFragment;
    }

    @Override
    protected void onFragmentViewClick(View view) {
        clearSelection();
        switch (view.getId()) {
            case R.id.llHome:
                mDataBinding.ivHome.setImageResource(R.drawable.sy);
                mDataBinding.tvHome.setTextColor(Color.parseColor("#5476FC"));
                break;
            case R.id.llWorkTime:
                mDataBinding.ivWorkTime.setImageResource(R.drawable.jgs);
                mDataBinding.tvWorkTime.setTextColor(Color.parseColor("#5476FC"));
                break;
            case R.id.llClockIn:
                mDataBinding.ivClockIn.setImageResource(R.drawable.dk);
                mDataBinding.tvClockIn.setTextColor(Color.parseColor("#5476FC"));
                break;
            case R.id.llMy:
                mDataBinding.ivMy.setImageResource(R.drawable.wd);
                mDataBinding.tvMy.setTextColor(Color.parseColor("#5476FC"));
                break;
        }
    }

    @Override
    protected int getFragmentContainerId() {
        return R.id.flHome;
    }

    @Override
    protected int onCreate() {
        return R.layout.activity_home;
    }

    private void clearSelection() {
        mDataBinding.ivHome.setImageResource(R.drawable.sywxz);
        mDataBinding.tvHome.setTextColor(Color.parseColor("#9D9C9C"));
        mDataBinding.ivWorkTime.setImageResource(R.drawable.jgswxz);
        mDataBinding.tvWorkTime.setTextColor(Color.parseColor("#9D9C9C"));
        mDataBinding.ivClockIn.setImageResource(R.drawable.dkwxz);
        mDataBinding.tvClockIn.setTextColor(Color.parseColor("#9D9C9C"));
        mDataBinding.ivMy.setImageResource(R.drawable.wdwxz);
        mDataBinding.tvMy.setTextColor(Color.parseColor("#9D9C9C"));
    }

}